package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目相关接口")
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 分页查询
     *
     * @param pageNum
     * @param pageSize
     * @param name
     * @param status
     * @return
     */
    @GetMapping
    @ApiOperation("分页条件查询护理项目")
    public PageResponse<NursingProjectVo> selectByPage(
            @ApiParam(value = "当前页码", required = true, example = "1") Integer pageNum,
            @ApiParam(value = "每页显示的数量", required = true, example = "10") Integer pageSize,
            @ApiParam(value = "护理项目名称，用于模糊搜索") String name,
            @ApiParam(value = "护理项目状态，用于精确筛选") Integer status) {

        return nursingProjectService.selectByPage(pageNum, pageSize, name, status);
    }

    /**
     * 新增护理项目
     *
     * @param nursingProjectDto
     * @return
     */
    @PostMapping
    @ApiOperation(value = "新增护理项目", notes = "接收护理项目详细信息并插入数据库。")
    public ResponseResult addNursingProject(@RequestBody @ApiParam(value = "护理项目实体对象", required = true) NursingProjectDto nursingProjectDto) {

        return toAjax(nursingProjectService.insert(nursingProjectDto));
    }

    /**
     * 根据id删除护理项目
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除护理项目", notes = "根据id删除护理项目。")
    public ResponseResult deleteNursingProject(@PathVariable @ApiParam(value = "护理项目id", required = true) Long id) {

        return toAjax(nursingProjectService.deleteById(id));
    }

    /**
     * 更新护理项目
     *
     * @param nursingProjectDto
     * @return
     */
    @PutMapping("/{id}")
    @ApiOperation(value = "更新护理项目")
    public ResponseResult updateNursingProject(@RequestBody @ApiParam(value = "护理项目实体对象", required = true) NursingProjectDto nursingProjectDto) {
        return toAjax(nursingProjectService.updateNursingProject(nursingProjectDto));
    }

    /**
     * 根据id查询护理项目
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理项目")
    public ResponseResult selectById(@PathVariable @ApiParam(value = "护理项目id", required = true) Long id) {
        return success(nursingProjectService.selectNursingProjectById(id));
    }

    /**
     * 查询所有护理项目
     *
     * @return ResponseResult 包含护理项目列表的响应结果
     */
    @GetMapping("/all")
    @ApiOperation(value = "查询所有护理项目", notes = "返回所有护理项目的信息")
    public ResponseResult<List<NursingProject>> getAllNursingProjects() {
        List<NursingProject> projects = nursingProjectService.getAllNursingProjects();
        return ResponseResult.success(projects);
    }


}
